<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- reduce map 迭代器，有什么不同 ①.实现函数：同时使⽤ reduce map 迭代 -->
</head>
<body>
  <script>
    let arr = [1,2,3,4,5,6,7,8]
    let arr2 = arr.map((item) => {
      if(item % 2 == 0){
        return item
      }
      return 0
    })
    console.log(arr2);
    let sum = arr2.reduce((a, b) => {
        return a + b
    }, 0)
    console.log(sum);

    let sum2 = arr.reduce((a, b) => {
      if(b % 2 != 0){
        return a + b
      }
      return a
    }, 0)
    console.log(sum2);
  </script>
</body>
</html>